package com.hongning.railway.ui.main.fragments.cadremanagement;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;

import com.hongning.railway.BR;
import com.hongning.railway.R;
import com.hongning.railway.data.AppRepository;
import com.hongning.railway.entity.reqbean.ReqCadreListBean;
import com.hongning.railway.entity.resbean.BaseResCadreListBean;
import com.hongning.railway.entity.resbean.ResCadreBean;
import com.hongning.railway.ui.main.cadremanager.CadreManagerFragmentViewModel;
import com.hongning.railway.ui.main.cadremanager.itemviewmodel.CadreManagerItemViewModel;
import com.hongning.railway.ui.main.fragments.cadremanagement.viewmodel.CadreKaoHeItemViewModel;
import com.hongning.railway.util.Apputils;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class CadreAssessmentViewModel extends BaseViewModel<AppRepository> {
    public ItemBinding<CadreKaoHeItemViewModel> item = ItemBinding.of(BR.viewModel, R.layout.item_cadrekaohe);
    public ObservableList<CadreKaoHeItemViewModel> viewlist= new ObservableArrayList();
    public CadreAssessmentViewModel(@NonNull Application application) {
        super(application);
    }

    public CadreAssessmentViewModel(@NonNull Application application, AppRepository model) {
        super(application, model);
    }

    public void loadData(){
        ReqCadreListBean reqCadreListBean = new ReqCadreListBean();
        reqCadreListBean.setStaffId(Apputils.getStaffid());
        //魔法值走起 我也不晓得啥意思 后台喊整的
        reqCadreListBean.setCadretesttype("2");
        model.getCadreList(reqCadreListBean)
                .compose(RxUtils.schedulersTransformer())
                .compose(RxUtils.bindToLifecycle(getLifecycleProvider()))
                .subscribe(new ApiDisposableObserver<BaseResCadreListBean<ResCadreBean>>() {
                    @Override
                    public void onResult(BaseResCadreListBean<ResCadreBean> resCadreBeanBaseResCadreListBean) {
                        for (ResCadreBean item:resCadreBeanBaseResCadreListBean.getData()) {
                            viewlist.add(new CadreKaoHeItemViewModel(CadreAssessmentViewModel.this,item));
                        }
                    }
                });
    }
}
